package com.vonchange.utils.tpl.res;

import java.io.IOException;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.vonchange.utils.res.min.JsMinUtils;
import com.vonchange.utils.tpl.DirectiveUtils;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
@Component
public class JsDirective implements TemplateDirectiveModel {
	private static final String PARAM_SRC = "src";
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
		String src = DirectiveUtils.getString(PARAM_SRC, params);
		String result=JsMinUtils.genSrc(src);
		env.getOut().append(result);
	}

}
